package com.cash.loan.modular.cash.controller;

import com.cash.loan.common.result.PageResult;
import com.cash.loan.common.result.ServerResponse;
import com.cash.loan.modular.cash.annotation.ScanLog;
import com.cash.loan.modular.cash.service.StrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @Date 2018-07-20 13:37
 */
@Api(description = "策略文章接口")
@RestController
@RequestMapping(value = "/strategy")
public class StrategyController {

    private static Logger logger = LoggerFactory.getLogger(StrategyController.class);

    @Autowired
    private StrategyService strategyService;

    @ApiOperation("文章列表")
    @GetMapping(value = "/list")
    public ServerResponse<PageResult<Map<String,Object>>> getStrategyList(@RequestParam(value = "currentPage",required = false,defaultValue = "1") Integer currentPage,
                                          @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize) {
        PageResult<Map<String,Object>> pageResult = strategyService.getList(currentPage,pageSize);
        return ServerResponse.getSuccess("success",pageResult);
    }

    @ApiOperation("文章搜索")
    @GetMapping(value = "/search")
    public ServerResponse<List<Map<String,Object>>> searchStrategy(@RequestParam(value = "keyword",required = false) String keyword) {
        List<Map<String,Object>> listResult = strategyService.searchStrategy(keyword);
        return ServerResponse.getSuccess("success",listResult);
    }

    @ApiOperation("文章详情")
    @GetMapping(value = "/detail")
    @ScanLog
    public ServerResponse<Map<String,Object>> getStrategyDetail(@RequestParam(value = "id") Long id) {
        Map<String,Object> detailResult = strategyService.getDetailById(id);
        return ServerResponse.getSuccess("success",detailResult);
    }

    @ApiOperation("全部类别")
    @GetMapping(value = "/listCate")
    public ServerResponse getAllStrategyType() {
        List<Map<String,Object>> typeResult = strategyService.getAllStrategyList();
        return ServerResponse.getSuccess("success",typeResult);
    }

    @ApiOperation("得到类别下的所有文章")
    @GetMapping(value = "/cateForArticle")
    public ServerResponse getStrategyByType(@RequestParam(value = "id") Integer id) {
        List<Map<String,Object>> listResult = strategyService.getStrategysByCateId(id);
        return ServerResponse.getSuccess("success",listResult);
    }
}
